﻿#pragma once
#include "Globalvf.h"
#include "lite_access.h"

#define DATA_SRC_SERVER   1
#define DATA_SRC_LOCAL    2
#define DATA_SRC_NONE     3

#define LOCAL_DYNSET_TABLLESPEC2		1
#define LOCAL_DYNSET_TABLLESPEC3		2
#define LOCAL_DYNSET_TYPESPEC2			3
#define LOCAL_DYNSET_TYPESPEC3			4
#define LOCAL_DYNSET_COLSPEC2			5
#define LOCAL_DYNSET_COLSPEC3			6

typedef struct __DATA_VAL__
{
	char *pVal;
	__DATA_VAL__ *pNext;
}DATA_VAL;

class CDBCEx;
class CSTMTEx
{
//▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
// Public 함수들.
//▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
public:
	CSTMTEx(const int nMyIndex,CDBCEx *pDbc);
	~CSTMTEx(void);
public: //Varibles.
	Lite_Stmt * m_pStmt;
    SQLCHAR cursorname[32];	/**< Cursor name */
	CDBCEx * m_pDbc;
	int m_nColCount;       ///< 컬럼 카운트.
	int m_nNatErr;
    int longnames;		/**< Don't shorten column names */
	int m_guessed_types;
	SQLCHAR m_szlogmsg[1024];	/**< Message for SQLError() */
    char   m_szSQLstate[6];		/**< SQL state for SQLError() */
	BOOL   m_bUse;
	COLEX *m_pDynCols;             /**< DynCols 정보 */
	int nowchar[2];		/**< Don't try to use WCHAR */
    int bkmrk;			/**< True when bookmarks used */
    int rowp;			/**< Current result row */
    int retr_data;		/**< SQL_ATTR_RETRIEVE_DATA */
    char *bincache;		/**< Cache for blob data */
    int binlen;			/**< Length of blob data */
	char *bincell;		/**< Cache for blob data */
    int *oemcp;			/**< True for Win32 OEM CP translation */
    int dobigint;		/**< Force SQL_BIGINT for INTEGER columns */
	BOOL m_bBind;       /**< Do Bind */
    int m_nCurType;		/**< Cursor type */
	short m_nDataSrc;        /**< 데이터에 대한 모드 */
	int m_nArrIdx;
private:
	//WCHAR  m_wcTemp[4096];
	SQLWCHAR m_ucdata[4096];
public:
	void SetState(int naterr, char *msg, char *st, ...);
	void Reset();

	BOOL Prepare(const char * pszSQL);   ///< Select문을 준비한다.
	int  Fetch();                        ///< 데이터를 가져 온다.
	int Fetch_org();                     ///< 데이터를 가져 온다.
	BOOL SetupDynCols();                 ///< SetupDynCols.
	void FixupDynCols();                 ///< FixUpDynCols.
	BOOL SetupLocalDynCols(int nType);   ///< 로컬 소스에 대한 Dyncols 세팅.
	const char * StmtColType(int col, int *guessed_types); ///< STMT 컬럼 Type을 결정한다.
	const char * Get_Column_Decltype(int N);
	int  Get_Column_Type(int N);
	void FreeDynCol();
	int Execute();
	int DescribeCol(SQLUSMALLINT col, SQLCHAR * name,
	       SQLSMALLINT nameMax, SQLSMALLINT *nameLen,
	       SQLSMALLINT *type, SQLULEN *size,
	       SQLSMALLINT *digits, SQLSMALLINT *nullable);
	int GetRowDataold(SQLUSMALLINT col, SQLSMALLINT otype, SQLPOINTER val, SQLINTEGER len, SQLLEN *lenp, int partial);
	int GetRowData(SQLUSMALLINT col, SQLSMALLINT otype, SQLPOINTER val, SQLINTEGER len, SQLLEN *lenp, int partial);
	void GetColumnInfo(); ///< 컬럼 정보를 가져 온다.
	int NoMemory();
	int BindCol(SQLUSMALLINT col, SQLSMALLINT type, SQLPOINTER val, SQLLEN max, SQLLEN *lenp);
	int DoFetchBind();
	BOOL GetTypeInfo(SQLSMALLINT sqltype);                ///< Type정보 함수.
	int GetTables(
	  SQLCHAR *cat, SQLSMALLINT catLen,
	  SQLCHAR *schema, SQLSMALLINT schemaLen,
	  SQLCHAR *table, SQLSMALLINT tableLen,
	  SQLCHAR *type, SQLSMALLINT typeLen);               ///< Table정보 함수.
	BOOL GetClolumn2(char *pszTABLE_NAME);               ///< 컬럼 정보 함수.
	const char * GetVal(int nIndex);                     ///< 0
	void  FreeData();                                 ///< DATA_VAL를 없앤다.
	void  ReadyFirstData();                              ///< 처음 데이터를 준비 한다.
	void  AddData(const char *pVal);                    ///< DATA_VAL를 추가한다.
	void  SetLocalData( BOOL bBool);                     ///< 데이터를 로컬로 맞춘다.
	//=======================================================
	// 
	//=======================================================
	CArray <char *,char *> m_arrVal;
};

